// DlgPickList.cpp : implementation file
//

#include "stdafx.h"
#include "Celsus.h"
#include "DlgPickList.h"


// CDlgPickList dialog

IMPLEMENT_DYNAMIC(CDlgPickList, CDialog)

CDlgPickList::CDlgPickList(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgPickList::IDD, pParent)
{
}

CDlgPickList::~CDlgPickList()
{
}

void CDlgPickList::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST_PICK, m_lbPickList);
}


BEGIN_MESSAGE_MAP(CDlgPickList, CDialog)
	ON_LBN_DBLCLK(IDC_LIST_PICK, &CDlgPickList::OnLbnDblclkListPick)
END_MESSAGE_MAP()


// CDlgPickList message handlers

BOOL CDlgPickList::OnInitDialog()
{
	CDialog::OnInitDialog();

	// check for empty
	if( m_pszaStrings->GetCount() <= 0 )
		GetDlgItem( IDOK )->EnableWindow( FALSE );

	// set item height
	m_lbPickList.SetItemHeight( 0, m_lbPickList.GetItemHeight(0) + 3 );

	// set items in list
	for( INT nIndex = 0; nIndex < m_pszaStrings->GetCount(); nIndex++ )
	{
		m_lbPickList.AddString( m_pszaStrings->GetAt( nIndex ));

		// should add item data to remove string search dependence
		//m_lbPickList.SetItemData( nIndex, 
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgPickList::OnOK()
{
	INT nSel = -1;
	nSel = m_lbPickList.GetCurSel();
	if( nSel < 0 )
	{
		CDialog::OnCancel();
		return;
	}

	// get picked
	m_lbPickList.GetText( m_lbPickList.GetCurSel(), m_szString );

	CDialog::OnOK();
}

void CDlgPickList::OnLbnDblclkListPick()
{
	// do Ok
	OnOK();
}
